<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ItemOrderReadDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateItemOrderReadRequest;
use App\Http\Requests\UpdateItemOrderReadRequest;
use App\Repositories\ItemOrderReadRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ItemOrderReadController extends AppBaseController
{
    /** @var  ItemOrderReadRepository */
    private $itemOrderReadRepository;

    public function __construct(ItemOrderReadRepository $itemOrderReadRepo)
    {
        $this->itemOrderReadRepository = $itemOrderReadRepo;
    }

    /**
     * Display a listing of the ItemOrderRead.
     *
     * @param ItemOrderReadDataTable $itemOrderReadDataTable
     * @return Response
     */
    public function index(ItemOrderReadDataTable $itemOrderReadDataTable)
    {
        return $itemOrderReadDataTable->render('backend.item_order_reads.index');
    }

    /**
     * Show the form for creating a new ItemOrderRead.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.item_order_reads.create');
    }

    /**
     * Store a newly created ItemOrderRead in storage.
     *
     * @param CreateItemOrderReadRequest $request
     *
     * @return Response
     */
    public function store(CreateItemOrderReadRequest $request)
    {
        $input = $request->all();

        $itemOrderRead = $this->itemOrderReadRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Item Order Read']));

        return redirect(route('itemOrderReads.index'));
    }

    /**
     * Display the specified ItemOrderRead.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Order Read']));

            return redirect(route('itemOrderReads.index'));
        }

        return view('backend.item_order_reads.show')->with('itemOrderRead', $itemOrderRead);
    }

    /**
     * Show the form for editing the specified ItemOrderRead.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Order Read']));

            return redirect(route('itemOrderReads.index'));
        }

        return view('backend.item_order_reads.edit')->with('itemOrderRead', $itemOrderRead);
    }

    /**
     * Update the specified ItemOrderRead in storage.
     *
     * @param  int              $id
     * @param UpdateItemOrderReadRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateItemOrderReadRequest $request)
    {
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Order Read']));

            return redirect(route('itemOrderReads.index'));
        }

        $itemOrderRead = $this->itemOrderReadRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Item Order Read']));

        return redirect(route('itemOrderReads.index'));
    }

    /**
     * Remove the specified ItemOrderRead from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Order Read']));

            return redirect(route('itemOrderReads.index'));
        }

        $this->itemOrderReadRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Item Order Read']));

        return redirect(route('itemOrderReads.index'));
    }
}
